/**
 * @projectName spring-boot-examples-master
 * @package com.neo.web
 * @className com.neo.web.RedisController
 * @copyright Copyright 2020 XiaoFeiPeng, Inc All rights reserved.
 */
package com.neo.web;

import com.neo.model.User;
import com.neo.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * RedisController
 * @description RedisController
 * @author jiangyunfei
 * @date 2023/6/16 16:07
 * @version 1.0
 */

@RestController
@RequestMapping("redis")
public class RedisController {

    private final RedisTemplate redisTemplate;

    @Autowired
    private RedisUtil redisUtil;

    public RedisController(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @GetMapping("/save")
    public String save(String key, String value){

        // 已经序列化了
        User user = new User("aa@126.com", "aa", "aa123456", "aa","123");
        redisTemplate.opsForValue().set("user:100",user);
        User o = (User)redisTemplate.opsForValue().get(key);
        String email = o.getEmail();
        o.setId(456455L);
        return o.toString();
    }


}
